package com.app.service.impl;

import com.app.mapper.IdeaMapper;
import com.app.model.IdeaModel;
import com.app.service.IdeaService;
import com.app.vo.IdeaVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IdeaServiceImpl extends ServiceImpl<IdeaMapper, IdeaModel> implements IdeaService {
    @Autowired
    private IdeaMapper ideaMapper;

    @Override
    public void add(IdeaModel idea) {
        ideaMapper.insert(idea);
    }

    @Override
    public List<IdeaModel> selectContent(Integer page, Integer limit, int userId) {

        List<IdeaModel> ideaModels = ideaMapper.selectContent((page - 1) * limit, limit, userId);
        return ideaModels;
    }

    @Override
    public IdeaVo selectIdea(Integer start, Integer limit, String keyword) {
        int page = (start - 1) * limit;
        List<IdeaModel> ideaModels = ideaMapper.selectIdea(page, limit, keyword);
        int count = selectIdeaCount();
        IdeaVo vo = new IdeaVo();
        vo.setList(ideaModels);
        vo.setCount(count);
        return vo;
    }

    @Override
    public int selectIdeaCount() {
        return ideaMapper.selectCount(null);
    }

    @Override
    public IdeaModel selectIdeaContent(Integer id) {
        return ideaMapper.selectIdeaContent(id);
    }

    @Override
    public int getCount() {
        return ideaMapper.getCount();
    }
}
